package pos.gengshen.com.gspos.utils;


import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

import java.util.Map;

/**
 * Created by Administrator on 2018/7/5/005.
 */



public class HttpUtil {

    public static void sendOKHttpRequest(String address, Map<String,String> head, Map<String,String> body, okhttp3.Callback callback){

        OkHttpClient client=new OkHttpClient();
        Request.Builder builder=new Request.Builder().url(address);
        if(head!=null&&head.size()>0){
            for (Map.Entry<String, String> entry : head.entrySet()) {
                builder.addHeader(entry.getKey(),entry.getValue());
            }
        }
        FormBody.Builder formBody = new FormBody.Builder();
        if(body!=null&&body.size()>0){
            for (Map.Entry<String, String> entry : head.entrySet()) {
                formBody.add(entry.getKey(),entry.getValue());
            }
        }
        RequestBody requestBody = formBody.build();
        //Request request=builder.post(requestBody).build();
        Request request=builder.get().build();
        client.newCall(request).enqueue(callback);
    }




}
